package com.example.shiwuyouproject.ui.fragment.home.viewmodel

import androidx.lifecycle.MutableLiveData
import com.example.shiwuyouproject.base.BaseBean
import com.example.shiwuyouproject.base.BaseViewModel
import com.example.shiwuyouproject.ui.fragment.home.bean.GetFavoriteStarBean
import com.example.shiwuyouproject.ui.fragment.home.bean.GetPostGetBean
import java.util.*

class CourseDetailsViewModel : BaseViewModel() {
    private val loginRepository by lazy { RetrofitClient.getApiService() }

    /**
     * 获取课程详细信息
     */
    val getPostGetStatus = MutableLiveData<GetPostGetBean>()
    fun getPostGet(post_id: String) {
        launch(
            block = {
                val codeStatus = loginRepository.getPostGet(post_id)
                getPostGetStatus.value = codeStatus.result()
            },
            error = {
            },
            cancel = {

            },
            showErrorToast = false
        )
    }

    /**
     * 收藏
     */
    val getFavoriteStarDelStatus = MutableLiveData<GetFavoriteStarBean>()
    fun getFavoriteStarDel(post_id: String, status: Boolean) {
        launch(
            block = {
                    val codeStatus = loginRepository.getFavoriteStar(post_id)
                    getFavoriteStarDelStatus.value = codeStatus.result()
            },
            error = {
            },
            cancel = {

            },
            showErrorToast = false
        )
    }
    /**
     * 申请课程
     */
    val getApplyAddStatus = MutableLiveData<BaseBean<Objects>>()
    fun getApplyAdd(org_id: String,post_id: String) {
        launch(
            block = {
                val codeStatus = loginRepository.getApplyAdd(org_id,post_id)
                getApplyAddStatus.value = codeStatus
            },
            error = {
            },
            cancel = {

            },
            showErrorToast = false
        )
    }
}